package com.atguigu.gmall.activity.service.impl;

import com.atguigu.gmall.activity.service.ActivityService;
import com.atguigu.gmall.product.client.common.constant.RedisConst;
import com.atguigu.gmall.product.client.model.activity.SeckillGoods;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ActivityServiceImpl implements ActivityService {

    @Autowired
    private RedisTemplate redisTemplate;

    //查询秒杀数据
    @Override
    public List<SeckillGoods> findAll() {

    return redisTemplate.opsForHash().values(RedisConst.SECKILL_GOODS);

    }

    //一个秒杀数据放入到缓存
    @Override
    public SeckillGoods findBySkuId(Long skuId) {
        return (SeckillGoods) redisTemplate.opsForHash().get(RedisConst.SECKILL_GOODS,skuId.toString());

    }
}
